//
//  Socket.h
//  http_server
//
//  Created by Zirpon Cheung on 15-3-24.
//  Copyright (c) 2015年 Zirpon Cheung. All rights reserved.
//

#ifndef __http_server__Socket__
#define __http_server__Socket__

//#include <iostream>

#include <arpa/inet.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <syslog.h>
#include <sys/socket.h>
#include <string.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <stdio.h>
#include <net/if.h>
#include <sys/ioctl.h>


#define MAXBUF 1024

class Socket
{
public:
    Socket();
    ~Socket();
    bool    init(const char *ip, unsigned short port, unsigned short back);
    int     create_listener();
    bool    set_reuse(int fd);
    bool    set_nonblocking(int fd);
    int     in_event();
    void    close();
    
    static bool getLocalhost(const char *netname, char* ip);

private:
    int             _fd;
    char* const     _host;
    unsigned short  _port;
    unsigned short  _back;
    
};

#endif /* defined(__http_server__Socket__) */



